/*
-----------------------------------------------------------------------------
This source file is part of Labor3D
(Labor 3D Graphics Engine)

Copyright (c) 2009-2020 Rock Mao
* creator : Rock Mao
* created : 2009-6-27   22:29
* filename: LaborD3D10HardwareBuffer.h
-----------------------------------------------------------------------------
*/
#ifndef __LABORD3D10HARDWAREBUFFER_H__
#define __LABORD3D10HARDWAREBUFFER_H__

#include "LaborD3D10Def.h"
#include "LaborD3D10Device.h"

NAMESPACE_LABOR3D_BEGIN

class CLD3D10HardwareBuffer : public CLHardwareBuffer
{	
protected:
	ID3D10Buffer*          mlpD3DBuffer;
	bool                   mUseTempStagingBuffer;
	CLD3D10HardwareBuffer* mpTempStagingBuffer;
	bool                   mStagingUploadNeeded;
	eLHardwareBufferType             mBufferType;
	CLD3D10Device &        mDevice;
	D3D10_BUFFER_DESC      mDesc;
	/** See HardwareBuffer. */
	void* lockImpl(size_t offset, size_t length, EHB_LockOptions options);
	/** See HardwareBuffer. */
	void unlockImpl(void);
public:
	CLD3D10HardwareBuffer(eLHardwareBufferType btype, size_t sizeBytes, EHB_Usage usage, 
		CLD3D10Device & device, bool useSystemMem, bool useShadowBuffer);
	~CLD3D10HardwareBuffer();
	/** See HardwareBuffer. */
	void readData(size_t offset, size_t length, void* pDest);
	/** See HardwareBuffer. */
	void writeData(size_t offset, size_t length, const void* pSource,
		bool discardWholeBuffer = false);
	/** See HardwareBuffer. We perform a hardware copy here. */
	void copyData(CLHardwareBuffer& srcBuffer, size_t srcOffset, 
		size_t dstOffset, size_t length, bool discardWholeBuffer = false);

	/// Get the D3D-specific buffer
	ID3D10Buffer* getD3DBuffer(void) { return mlpD3DBuffer; }

};
NAMESPACE_LABOR3D_END
#endif // __LABORD3D10HARDWAREBUFFER_H__